package cn.dengta.webapp.im.dto;

import java.io.Serializable;
import java.util.Map;
import javax.annotation.Nonnull;

import cn.dengta.context.model.Language;
import cn.dengta.webapp.im.service.RemoteImService;
import cn.dengta.webapp.trade.vo.UserGiftVO;
import cn.dengta.webapp.user.entity.User;
import cn.dengta.webapp.user.model.UserSketch;
import com.alibaba.fastjson2.JSONObject;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

@Getter
@Setter
@Accessors(chain = true)
public class GiftMsgDTO implements Serializable {

	private static final long serialVersionUID = 1L;

	/** 发送者 */
	public String fromUserId;
	public Map<String, Object> fromUser;
	/** 礼物消息数据载体 */
	public UserGiftVO vo;
	/** 接收者 */
	public String toUserId;
	/** 接收者语言（用于国际化） */
	public Language toUserLang;

	public Long toGroupId;

	/** 直播间钻石总消耗 */
	public Long totalCoin;
	/** 是否Ai */
	public Boolean isAi;


	public Long originFromUserId, originToUserId;

	public GiftMsgDTO init(Long fromUserId, UserGiftVO vo, Long toUserId, @Nonnull Language toUserLang) {
		originFromUserId = fromUserId;
		originToUserId = toUserId;
		this.fromUserId = RemoteImService.toAccid(fromUserId);
		this.vo = vo;
		this.toUserId = RemoteImService.toAccid(toUserId);
		this.toUserLang = toUserLang;
		return this;
	}

	public GiftMsgDTO init(Long fromUserId, UserGiftVO vo, UserSketch toUser) {
		return init(fromUserId, vo, toUser.getId(), toUser.getLanguage());
	}

	public GiftMsgDTO init(Long fromUserId, boolean isAi, Long toUserId, UserGiftVO vo, Language language) {
		originFromUserId = fromUserId;
		originToUserId = toUserId;
		this.fromUserId = RemoteImService.toAccid(fromUserId);
		this.vo = vo;
		this.toUserId = isAi ? RemoteImService.toAiIdAccid(toUserId) : RemoteImService.toAccid(toUserId);
		this.toUserLang = language;
		return this;
	}

	public GiftMsgDTO init(UserSketch fromUser, UserGiftVO vo, UserSketch toUser) {
		final GiftMsgDTO dto = init(fromUser.getId(), vo, toUser.getId(), toUser.getLanguage());
		dto.fromUser = User.asEmbed(fromUser);
		return dto;
	}

}
